import { Component, OnInit } from '@angular/core';
import{EventService}from'../../services/event.service';
import {Storage} from "@ionic/storage";
import { Router} from '@angular/router'
@Component({
  selector: 'app-login',
  templateUrl: './login.page.html',
  styleUrls: ['./login.page.scss'],
})
export class LoginPage implements OnInit {


  constructor(public storage: Storage,public router:Router,public eventService: EventService) { }

  ngOnInit() {
  }

  _login(username: HTMLInputElement, password: HTMLInputElement){

    if (username.value.length === 0){
      //this.showToast("bottom", "请输入");
      return false;
    }

    if (password.value.length === 0){
      //this.showToast("bottom", "请输入密码");
      return false;
    }

    let data = {username: username.value, password: password.value};

    console.log(data);

    // 储存用户信息
    this.storage.remove("USER_INFO");
    this.storage.set("USER_INFO", data);

    this.storage.set("isLoginEd", true);

    // 界面跳转
    this.router.navigate(['/tabs/tab3']);
  }

  // 离开页面通知首页刷新
  ionViewDidLeave(){
    this.eventService.event.emit('login');
  }

}
